package cn.tedu.imop.mq.service;

import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.concurrent.CompletableFuture;

@Service
public class MessageSenderSerivce {
    private RabbitTemplate rabbitTemplate;
    public MessageSenderSerivce(RabbitTemplate rabbitTemplate) {
        this.rabbitTemplate = rabbitTemplate;
        this.rabbitTemplate.setConfirmCallback((correlationData,ack,cause)->{
            if(!ack){
               //sendNotices(msg);
               //saveSendError(msg);
               //sendMessage(msg);
            }
        });
    }
    public void sendMessage(String msg) {
        CorrelationData correlationData = new CorrelationData();
        rabbitTemplate.convertAndSend("exc.direct", "red", msg, correlationData);
    }
}
